class Solution:
    def reverse(self, x: int) -> int:
        isNegative = False
        sum = 0
        if x == 0:
            print(0)
        if x < 0:
            isNegative = True
            x = -x
        count = len(str(x)) - 1
        while x != 0:
            r = x % 10
            x = int(x / 10)
            sum += r * (10 ** count)
            count -= 1
        if isNegative:
            sum = -sum
        if sum > (2 ** 31) - 1 or sum < -(2 ** 31):
            sum = 0
        return sum


solution = Solution()

print(solution.reverse(1534236469))

# Accepted
# Runtime: 36 ms, faster than 94.24% of Python3 online submissions for Reverse Integer.
# Memory Usage: 13.2 MB, less than 61.55% of Python3 online submissions for Reverse Integer.
